<?php

class mads extends CI_Model{
    
    private $tbl = "ads";
    public $_format = "Y-m-d";
    
    public function fetchAll(){
        return $this->db->get($this->tbl)->result();
    }
    
    public function fetchOne($id){
        return $this->db->where('id',$id)->get($this->tbl)->row();
    }
    
    public function insert($arr = array()){
        $this->db->insert($this->tbl,$arr);
    }
    
    public function update($id,$arr = array()){
        $this->db->where('id',$id)->update($this->tbl,$arr);
    }
    
    public function delete($id){
        $this->db->delete($this->tbl, array('id' => $id)); 
    }
    
    public function deleteAll(){
        $this->db->empty_table($this->tbl);  
    }
    
    public function getAds(){
        $time = gmdate($this->_format, time() + 7*3600);
        $array = array('date_start <=' => $time, 'date_end >=' => $time);
        return $this->db->where($array)->get($this->tbl)->result();
    }
      
}
